//引入express模块
const express = require('express');
//引入连接池
const pool = require('../pool.js');
//创建路由器
const r = express.Router();
//http://127.0.0.1:8080/v1/alter
r.put('/',(req,res,next)=>{
    let obj = req.body;
    console.log(obj);
    let i = 400;
    //循环各项不能为空
	for( let k in obj ){
		i++;
		//console.log(k,obj[k]);
		//如果属性值obj[k]为空，则提示k这项不能为空
		if(!obj[k]){
			res.send({code:i,msg:k+'不能为空'});
			return;
		}
	}
    //运行sql
    pool.query('update scp_clothes_family set ? where did=?',[obj,obj.did],(err,result)=>{
        if(err){
            next(err);
            return;
        }
        console.log(result);
        if(result.affectedRows === 0){
			res.send({code:201,msg:'修改失败'});
		}else{
			res.send({code:200,msg:'修改成功'});
		}
    });
});



//导出路由器
module.exports = r;